<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>state简写</title>
</head>
<body>
  <div id="app"></div>

  
    <!-- 引入文件 -->
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

<script type="text/babel">
// 1.创建类式组件
class MyCpn extends React.Component{
  // 类中可以直接写赋值语句
  // 给state赋值
  state = {
      isHot:true,
      type:'哇哈哈椰奶'
  }
  render(){
    return <h2 onClick={this.changeFn}>{this.state.type}现在是{this.state.isHot?'热的':'冷的'}</h2> 
  }
  // 使用箭头函数
  changeFn = ()=>{
    // 获取原来的isHot值
    const isHot = this.state.isHot
    this.setState({isHot:!isHot})

  }
}
// 2.渲染组件
ReactDOM.render(<MyCpn/>,document.getElementById('app'))

</script>


</body>
</html>